package types

import "database/sql"

// Model 模型结构
type Model struct {
	Name    string  `yaml:"name"`
	Table   string  `yaml:"table"`
	Comment string  `yaml:"comment"`
	Fields  []Field `yaml:"fields"`
}

// ModelConfig 模型配置结构
type ModelConfig struct {
	Model Model `yaml:"model"`
}

// Field 字段配置
type Field struct {
	Name     string      `yaml:"name"`
	Type     string      `yaml:"type"`
	Size     int         `yaml:"size,omitempty"`
	Primary  bool        `yaml:"primary,omitempty"`
	Unique   bool        `yaml:"unique,omitempty"`
	Required bool        `yaml:"required,omitempty"`
	Default  interface{} `yaml:"default,omitempty"`
	Comment  string      `yaml:"comment"`
}

// TemplateData 模板数据
type TemplateData struct {
	ModelName      string
	ModelNameCamel string
	ModelNameSnake string
	TableName      string
	Comment        string
	Fields         []Field
	PackageName    string
	LowerName      string
	ModulePath     string
}

// GeneratorConfig 生成器配置结构
type GeneratorConfig struct {
	Generator struct {
		Name    string `yaml:"name"`
		Version string `yaml:"version"`
		Author  string `yaml:"author"`
	} `yaml:"generator"`
	Paths struct {
		ProjectRoot    string `yaml:"project_root"`
		ModelsConfig   string `yaml:"models_config"`
		BackendOutput  string `yaml:"backend_output"`
		FrontendOutput string `yaml:"frontend_output"`
		TempDir        string `yaml:"temp_dir"`
		TemplatesDir   string `yaml:"templates_dir"`
	} `yaml:"paths"`
	Database struct {
		Driver      string   `yaml:"driver"`
		Host        string   `yaml:"host"`
		Port        int      `yaml:"port"`
		Username    string   `yaml:"username"`
		Password    string   `yaml:"password"`
		Database    string   `yaml:"database"`
		Charset     string   `yaml:"charset"`
		SSLMode     string   `yaml:"ssl_mode"`
		ConfigPaths []string `yaml:"config_paths"`
	} `yaml:"database"`
	Generation struct {
		OverwriteExisting bool   `yaml:"overwrite_existing"`
		GenerateBackend   bool   `yaml:"generate_backend"`
		GenerateFrontend  bool   `yaml:"generate_frontend"`
		AutoFormat        bool   `yaml:"auto_format"`
		PackagePrefix     string `yaml:"package_prefix"`
	} `yaml:"generation"`
}

// DatabaseConfig 数据库配置（与config.yaml保持一致）
type DatabaseConfig struct {
	Driver   string `yaml:"driver"`
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Database string `yaml:"database"`
	Charset  string `yaml:"charset"`
	SSLMode  string `yaml:"ssl_mode"`
}

// AppConfig 应用配置（用于读取config.yaml）
type AppConfig struct {
	Database DatabaseConfig `yaml:"database"`
}

// TableColumn 数据库表列信息
type TableColumn struct {
	Name     string
	Type     string
	Nullable bool
	Key      string
	Default  sql.NullString
	Extra    string
	Comment  string
}

// TableInfo 数据库表信息
type TableInfo struct {
	Name    string
	Comment string
	Columns []TableColumn
}

// ModuleInfo 模块信息
type ModuleInfo struct {
	Name      string
	LowerName string
	TableName string
	Comment   string
}